<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed.');
    class Client_m extends CI_Model {
        function __construct() {
            parent::__construct();
            $this->load->model('coordinator_m');
        }
        
        function get_clients() {
            $sql = "SELECT client_id, CONCAT(client_lname,', ',client_fname) AS name, client_email, 
                client_address, client_num, client_lname, client_fname FROM client ORDER BY client_lname";
            $q = $this->db->query($sql);
            if($q->num_rows() > 0) {
                return $q->result_array();
            }else{
                return FALSE;
            }
        }
        
        function get_event_clients(){
            $sql = "SELECT client_id, CONCAT(client_lname,', ',client_fname) AS name, client_email, 
                client_address, client_num, client_lname, client_fname FROM client WHERE event_id IS NULL ORDER BY client_lname";
            $q = $this->db->query($sql);
            if($q->num_rows() > 0) {
                return $q->result_array();
            }else{
                return FALSE;
            }
        }
        
        function get_client($id) {
            $q = $this->db->where('client_id', $id)->get('client');
            if($q->num_rows() > 0) {
                return $q->row();
            }else{
                return FALSE;
            }
        }
        
        function get_num_clients() {
            $q = $this->db->get('client');
            return $q->num_rows();
        }
        
        function check_if_client_exist($lname, $fname){
            $q = $this->db->where('client_lname', $lname)->where('client_fname', $fname)
                    ->get('client');
            return $q->num_rows();
        }
        
        function insert_client($data) {
            $this->db->insert('client', $data);
            return $this->db->insert_id();
        }
        
        function update_client($id, $data) {
            $client = array(
                'client_fname' => $data['client_fname'],
                'client_lname' => $data['client_lname'],
                'client_address' => $data['client_address'],
                'client_num' => $data['client_num'],
                'client_email' => $data['client_email'],
            );
            $this->db->where('client_id', $id)->update('client', $client);
            return $this->db->affected_rows();
        }
        
        function delete_client($client_id) {
            for($i=0;$i<sizeof($client_id);$i++){
                $this->db->where('client_id', $client_id[$i])->delete('client');
            }
        }
    }